unit ini;

interface

uses
  Sysutils, Debug, iniFiles, PakFile, Classes;

type
  Tini = class
    //FName: String;
    inifile: TiniFile;
    Pak: TPakFile;
    constructor Create;
    Destructor Destroy; override;
    procedure ClearFile;
    procedure CreateFile(IniName: string);
    procedure CreatePak(PakName, IniName: string);
    procedure release;
    function FileReadString(FName: String; Section, IDent, Default: String): String;
    function ReadString(Section, IDent, Default: String): String;
    function FileReadinteger(FName: String; Section, IDent: String; Default: integer): integer;
    function Readinteger(Section, IDent: String; Default: integer): integer;
    function FileReadbool(FName: String; Section, IDent: String; Default: boolean): boolean;
    function Readbool(Section, IDent: String; Default: boolean): boolean;
    function FileReadFloat(FName: String; Section, IDent: String; Default: Double): Double;
    function ReadFloat(Section, IDent: String; Default: Double): Double;
  end;

  Pini = ^Tini;

var
  CINI: Tini;

implementation

constructor Tini.Create;
begin
  inherited;
  iniFile := nil;
  Pak := TPakFile.Create;
end;

Destructor Tini.Destroy;
begin
  Release;
  inherited Destroy;
end;

procedure Tini.release;
begin
  ClearFile;
  Pak.Destroy;
end;

procedure Tini.ClearFile;
begin
  if inifile <> nil then
  begin
    inifile.Free;
    inifile := nil;
  end;
end;

procedure Tini.CreateFile(IniName: string);
begin
  iniFile := TiniFile.Create(IniName);
end;

procedure Tini.CreatePak(PakName, IniName: string);
var
  rs: TMemoryStream;
begin
  Pak.ReadFromFileToBuffer(PakName, IniName);
  rs := TMemoryStream.create;
  rs.SetSize(Pak.bufferlen);
  rs.Position := 0;
  rs.Write(Pak.databuffer, Pak.bufferlen);
  Pak.ClearBuffer;
  iniFile := TiniFile.Create(rs);
  rs.Free;
end;

function Tini.FileReadbool(FName: String; Section, IDent: String; Default: boolean): boolean;
var
  inif: TiniFile;
begin
  try
    inif := TiniFile.Create(Fname);
    result := iniF.Readbool(Section, IDent, Default);
  finally
    inif.Free;
  end;
end;

function Tini.Readbool(Section, IDent: String; Default: boolean): boolean;
begin
  result := iniFile.Readbool(Section, IDent, Default);
end;

function Tini.FileReadinteger(FName: String; Section, IDent: String; Default: integer): integer;
var
  inif: TiniFile;
begin
  try
    inif := TiniFile.Create(Fname);
    result := iniF.Readinteger(Section, IDent, Default);
  finally
    inif.Free;
  end;
end;

function Tini.Readinteger(Section, IDent: String; Default: integer): integer;
begin
  result := iniFile.Readinteger(Section, IDent, Default);
end;

function Tini.ReadString(Section, IDent, Default: String): String;
begin
  result := iniFile.ReadString(Section, IDent, Default);
end;

function Tini.FileReadString(FName: String; Section, IDent, Default: String): String;
var
  inif: TiniFile;
begin
  try
    inif := TiniFile.Create(Fname);
    result := iniF.ReadString(Section, IDent, Default);
  finally
    inif.Free;
  end;
end;

function Tini.FileReadFloat(FName: String; Section, IDent: String; Default: Double): Double;
var
  inif: TiniFile;
begin
  try
    inif := TiniFile.Create(Fname);
    result := iniF.ReadFloat(Section, IDent, Default);
  finally
    inif.Free;
  end;
end;

function Tini.ReadFloat(Section, IDent: String; Default: Double): Double;
begin
  result := iniFile.ReadFloat(Section, IDent, Default);
end;

end.
